package com.mxm.app.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button but1,but2,but3;
    private TextView main_view1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        main_view1 = findViewById(R.id.main_View1);
        but1 = findViewById(R.id.main_but1);
        but2 = findViewById(R.id.main_but2);
        but3 = findViewById(R.id.main_but3);
        but1.setOnClickListener(this);
        but2.setOnClickListener(this);
        but3.setOnClickListener(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        String txt = data.getStringExtra("txt");//获取子页面传来的数据
        main_view1.setText(txt);//显示到页面
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onClick(View v) {
        Intent  i;
        switch (v.getId()){
            case R.id.main_but1:
                i = new Intent(MainActivity.this,Test1.class);//设置跳转路径
                i.putExtra("txt","子页面收到主页面内容");//传输数据到打开页面
//                startActivity(i);//执行方法
                startActivityForResult(i,0);//执行方法
            break;
            case R.id.main_but2:
               i = new Intent(MainActivity.this,Test2.class);//设置跳转路径
                startActivity(i);//执行方法
            break;
            case R.id.main_but3:
               i = new Intent(MainActivity.this,Test3.class);//设置跳转路径
                startActivity(i);//执行方法
            break;
        }
    }
}
